<?php

/**
 * This is the model class for table "ld_user".
 *
 * The followings are the available columns in table 'ld_user':
 * @property integer $user_id

 * @property string $user_name
 * @property string $password
 * @property string $lr_acc
 * @property string $email
 * @property string $date_reg
 * @property double $lr_money
 * @property string $last_login
 * @property string $last_ip
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ld_user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('lr_money', 'numerical'),
			//array('id_ref', 'numerical'),
			array('phone', 'length','max'=>15),
			array('user_name', 'length', 'max'=>20),
			array('password, email', 'length', 'max'=>100),
			array('lr_acc', 'length', 'max'=>50),
			array('date_reg', 'safe'),
            array('user_name','unique','message'=>'Tên tài khoản này đã được sử dụng'),
            array('email','unique','message'=>'Email này đã được sử dụng'),
			array('phone','unique','message'=>'Số điện thoại này đã được sử dụng'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, user_name, password, lr_acc, email, date_reg, lr_money', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'user_name' => 'User Name',
			'password' => 'Password',
			'lr_acc' => 'Lr Acc',
			'email' => 'Email',
			'date_reg' => 'Date Reg',
			'lr_money' => 'Lr Money',
				
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('user_name',$this->user_name,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('lr_acc',$this->lr_acc,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('date_reg',$this->date_reg,true);
		$criteria->compare('lr_money',$this->lr_money);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}